class Qskill extends AcGameObject {
    constructor(playground, color, player) {
        super();
        this.playground = playground;
        this.player = player;
        this.ctx = this.playground.game_map.ctx2;
        this.x = this.ctx.canvas.width * 3 / 10;
        this.y = this.ctx.canvas.height / 2;
        this.radius = this.y;
        this.color = color;
        this.eps = 0.1;
        this.spent_time = 0;
    }

    start() {
        this.ctx.beginPath();
        this.ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2, false);
        this.ctx.closePath();
        this.ctx.fillStyle = this.color;
        this.ctx.fill();
    }

    update() {
        
        this.spent_time += this.timedelta / 1000;

        this.render();
    }

    render() {
        let angle = Math.PI * 2, color_ball = this.color;
        let player = this.player;
        angle = player.fireball_num / player.fixed_fireball_num * angle;
        if(!player.fireball_num){
            angle = (player.spent_time - player.last_fireball_time) / player.fireball_cd * Math.PI * 2;
            if(angle <= Math.PI * 2) color_ball = 'grey';
        }
        // console.log(player.fireball_num);
        // console.log(angle);
        // this.ctx.beginPath();
        // this.ctx.arc(this.x, this.y, this.radius, -Math.PI / 2, angle - Math.PI / 2);
        // this.ctx.closePath();
        // this.ctx.fillStyle = color_ball;
        // this.ctx.fill();
        this.ctx.beginPath();
        this.ctx.moveTo(this.x, this.y); // 从圆心开始
        this.ctx.arc(this.x, this.y, this.radius, -Math.PI / 2, -Math.PI / 2 + angle); // 绘制从顶部开始的圆弧
        this.ctx.closePath(); // 回到圆心，形成扇形
        this.ctx.fillStyle = color_ball; // 设置扇形颜色
        this.ctx.fill(); // 填充扇形


        this.ctx.fillStyle = '#000'; // 设置文字颜色;
        this.ctx.font = '25px Arial'; // 设置文字大小和字体
        this.ctx.textAlign = 'center'; // 文字居中对齐
        this.ctx.textBaseline = 'middle'; // 文字垂直居中对齐
        this.ctx.fillText('Q', this.x, this.y);
    }
}
